package com.ereport.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;


import com.ereport.entity.AdminExeBudget;
import com.ereport.entity.DailyActivity;
import com.ereport.util.ApplicationContext;

public class AdminExeBudgetDAO {
static Transaction tx;
	
	private  void endOperations(Session session) {
		
		session.close();
		session=null;
	}

	private  Session startOperations()throws Exception {
		
		Session session = ApplicationContext.getHiberSession().openSession();
		tx=session.beginTransaction();
		return session;
		
	}

	public int insert(AdminExeBudget ae) throws Exception {
		Session session = startOperations();
		session.saveOrUpdate(ae);
		session.getTransaction().commit();
		endOperations(session);
		return 0;
		
	}

	public List<AdminExeBudget> getExeBudget(int id, int exeid, String fyear) throws Exception {
		List<AdminExeBudget> aeb=new ArrayList<AdminExeBudget>();
		Session session=startOperations();
		Query qry=session.createQuery("from AdminExeBudget where admin_id=:id and exe_id=:exeid and fyear=:fyear");
		qry.setInteger("id", id);
		qry.setInteger("exeid", exeid);
		qry.setString("fyear",fyear);
		aeb=qry.list();
		endOperations(session);
		return aeb;
	}

	public void deletAdminExeBudget(int id, int exeid, String fyear) throws Exception {
		Session session=startOperations();
		String qtr="delete from AdminExeBudget where admin_id=:id and exe_id=:exeid and fyear=:fyear";
		Query qry=session.createQuery(qtr);
		qry.setInteger("id", id);	
		qry.setInteger("exeid", exeid);	
		qry.setString("fyear", fyear);	
		qry.executeUpdate();
		endOperations(session);
		return ;
		
	}

	
	
}
